﻿using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StarExplosionOrangeCtrl : MonoBehaviour
{
    public GameObject star;
    public GameObject explosion;

    public void StartDelay(Transform target)
    {
        StartCoroutine (Delay (target));
    }

    IEnumerator Delay (Transform target)
    {
        Debug.Log ($"Delay ");
        GameObject obj = Instantiate (star, transform);
        GameObject clone = null;
        obj.transform.position = Camera.main.ScreenToWorldPoint (Input.mousePosition);
        Sequence quence = DOTween.Sequence ();
        quence.Append (obj.transform.DOLocalMove (target.localPosition, 1f));
        quence.InsertCallback (1,
            delegate {
                Destroy (obj);
                clone = Instantiate (explosion, transform);
                clone.transform.position = target.position;
            });
        quence.InsertCallback (2,
            delegate { Destroy (clone); }
            );
        yield return null;
    }

    private void Init()
    {
        //GameObject clone;
        
    }
}
